package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.order.OrderFeign;
import com.atguigu.gmall.model.order.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/15 1:47
 */
@Controller
public class PayController {
    @Autowired
    private OrderFeign orderFeign;
    //pay.html?orderId=1174163683907993601
    @GetMapping("/pay.html")
    public String pay(@RequestParam("orderId") Long orderId, Model model){
        Result<OrderInfo> orderInfoResult = orderFeign.infoById(orderId);
        if (orderInfoResult.getCode() == 200){
            OrderInfo orderInfo = orderInfoResult.getData();
            model.addAttribute("orderInfo",orderInfo);
        }
        return "payment/pay";
    }
    //payment.gmall.com/pay/success.html
    @GetMapping("/pay/success.html")
    public String success(@RequestParam("out_trade_no") String outTradeNo){
        //支付成功后跳转到此页面,需要订单自检,自动查询订单状态,根据支付宝返回的结果更新订单状态
        //orderFeign.checkOrderStatusByAliPay(outTradeNo);
        //使用mq异步更新订单状态,保证订单的最终一致性
        return "payment/success";
    }
}
